package com.glomozda.machinerepairdao.domain.user;

import com.glomozda.machinerepairdao.security.BCrypt;

@SuppressWarnings({"PMD.CommentRequired", "PMD.LawOfDemeter"})
public class User {
	private Integer userID;
	private String login;
	private String password;
	private String passwordText;
	
	public User(){
	}

	public User(final String login, final String passwordText) {
		this.login = login;
		this.passwordText = passwordText;
		this.password = BCrypt.hashpw(passwordText, BCrypt.gensalt());
	}	
	
	public Integer getUserID() {
		return userID;
	}
	
	public void setUserID(final Integer userID) {
		this.userID = userID;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(final String login) {
		this.login = login;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(final String password) {
		this.password = password;
	}
	
	public String getPasswordText() {
		return passwordText;
	}

	public void setPasswordText(final String passwordText) {
		this.passwordText = passwordText;
	}

	@Override
	public int hashCode() {
		int hash = 3;
		hash = 13 * hash + (this.login != null ? this.login.hashCode() : 0);		
		return hash;
	}

	@Override
	public boolean equals(final Object obj) {
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final User other = (User) obj;
		if ((this.login == null) ? other.login != null : !this.login.equals(other.login)) {
			return false;
		}
		return true;
	}    

	@Override
	public String toString() {
		return "user{" + "userID=" + userID + ", login=" + login + ", password=" + password + ", passwordText=" + passwordText + '}'+"\n";
	}
}
